{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f707e19e-0d60-4c58-ae0e-ea9d5e674b88",
   "metadata": {},
   "source": [
    "柱形图与折线图的整合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "abd23e23-7c95-47af-8e56-f026dc8e5ed9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'D:\\\\jupyter\\\\线条与柱形图.html'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts.charts import Bar,Line\n",
    "from pyecharts import options as opts\n",
    "\n",
    "x_data = [\"1月\",\"2月\",\"3月\",\"4月\",\"5月\",\"6月\",\"7月\",\"8月\",\"9月\",\"10月\",\"11月\",\"12月\"]\n",
    "\n",
    "bar = (\n",
    "    Bar()\n",
    "    .add_xaxis(xaxis_data=x_data)\n",
    "    .add_yaxis(\n",
    "        series_name=\"蒸发量\",\n",
    "        y_axis=[2.0,4.9,7.0,23.5,25.6,45.6,9.0,4.8,15.3,19.1,35.5,40.3],\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "        )\n",
    "    .add_yaxis(\n",
    "        series_name=\"降水量\",\n",
    "        y_axis=[2.9,4.9,8.9,23.8,25.9,45.0,9.9,4.5,15.9,19.0,35.8,40.3],\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "        )\n",
    "    .extend_axis(\n",
    "        yaxis=opts.AxisOpts(  # 追加y轴\n",
    "            name='温度',\n",
    "            type_='value',\n",
    "            min_=0,\n",
    "            max_=25,\n",
    "            interval=5,\n",
    "            axislabel_opts=opts.LabelOpts(formatter=\"{value}摄氏度\")\n",
    "        )\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        tooltip_opts=opts.TooltipOpts(\n",
    "            is_show=True,\n",
    "            trigger='axis',axis_pointer_type='cross'\n",
    "        ),\n",
    "        xaxis_opts=opts.AxisOpts(\n",
    "            type_=\"category\",\n",
    "            axispointer_opts=opts.AxisPointerOpts(is_show=True,type_=\"shadow\")\n",
    "        ),\n",
    "        yaxis_opts=opts.AxisOpts(\n",
    "            name=\"\",\n",
    "            type_=\"value\",\n",
    "            min_=0,\n",
    "            max_=250,\n",
    "            interval=50,\n",
    "            axislabel_opts=opts.LabelOpts(formatter=\"{value}ml\"),\n",
    "            axistick_opts=opts.AxisTickOpts(is_show=True),\n",
    "            splitline_opts=opts.SplitLineOpts(is_show=True)\n",
    "        )\n",
    "    )\n",
    ")\n",
    "line = (\n",
    "    Line()\n",
    "    .add_xaxis(xaxis_data=x_data)\n",
    "    .add_yaxis(\n",
    "        series_name='平均温度',\n",
    "        yaxis_index=1,\n",
    "        y_axis=[2.0,2.2,2.3,3.3,4.5,6.3,10.2,20.3,23.4,23.0,16.5,12.6],\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )\n",
    ")\n",
    " # 表示折线图在柱形图之上\n",
    "bar.overlap(line).render(\"线条与柱形图.html\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
